package org.example.test.t1
import com.baomidou.mybatisplus.annotation.*
import com.baomidou.mybatisplus.core.MybatisSqlSessionFactoryBuilder
import com.baomidou.mybatisplus.core.mapper.BaseMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import org.apache.ibatis.annotations.Options
import org.apache.ibatis.annotations.Select
import org.apache.ibatis.session.SqlSession
import java.io.FileInputStream
import java.util.*

data class User(
    val id: Long,
    val id1: Long,
    val name: String,
    val nameasdasd1: String,
    val namedfsdfsf2: String,
    val namegfgdghd3: String,
    val roles: List<String>
)
interface WPlayerMapper : BaseMapper<W_Player> {
    @Options(fetchSize = 50000)
    @Select("SELECT id,\n" +
            "    world_id,\n" +
            "    aav,\n" +
            "    unit_task_id,\n" +
            "    leave_alliance_count,\n" +
            "    next_join_alliance_time,\n" +
            "    alliance_at,\n" +
            "    guide_list,\n" +
            "    combine_mail_id,\n" +
            "    now_effect_num,\n" +
            "    last_effect_time,\n" +
            "    today_num,\n" +
            "    last_get_time,\n" +
            "    today_donate_time,\n" +
            "    alliance_gift_map,\n" +
            "    delM_max_id,\n" +
            "    del_id_map,\n" +
            "    today_open_gift_count,\n" +
            "    ref_open_gift_count_time,\n" +
            "    invite_time,\n" +
            "    waijiao_count,\n" +
            "    last_waijiao_time,read_diplomacy_time,\n" +
            "    last_alliance_boss_reward_index,\n" +
            "    coin_lmt_map,\n" +
            "    big_gift_strings_list,\n" +
            "    revive_task_score,\n" +
            "    revive_task_id,\n" +
            "    next_npc_city_daily_reward_time,\n" +
            "    farm_data,\n" +
            "    boss_data,\n" +
            "    relic_data,\n" +
            "    mass_data,\n" +
            "    world_boss_data,\n" +
            "    player_alliance_competition,\n" +
            "    donate_score,\n" +
            "    npc_city_score,\n" +
            "    npc_city_day_score,\n" +
            "    npc_city_week_score,\n" +
            "    combined_global_buff_id,\n" +
            "    expire_time,\n" +
            "    remove_global_buff_ids,\n" +
            "    player_jjc,\n" +
            "    donate_day_score,\n" +
            "    donate_week_score,\n" +
            "    friend_apply_require_lv,\n" +
            "    alliance_arpg_vo,\n" +
            "    player_capital,\n" +
            "    small_black_vo,\n" +
            "    big_arms_race_data,\n" +
            "    player_army_activity,\n" +
            "    player_expedition,\n" +
            "    activity_data,\n" +
            "    room_chat_records" +

            " FROM w_player")
    fun selectAllPlayers(): List<W_Player>
}
class WorldPurActivityData(
    var activityId: Int = 0,
    var overTime: Long = 0L, // 活动结束时间
    var dropRecMap: HashMap<Int, WorldPurActivityRandomDropRecord> = hashMapOf(), // 掉落数据
)
data class PlayerExpeditionVo(
    var leftPlayCount: Int = 0, // 剩余游玩次数
    var nextRefPlayerCountTime: Long = 0,   // 下次刷新游玩次数的时间

    var leftBlessCount: Int = 0,    // 剩余祝福次数
    var nextRefBlessTime: Long = 0,    // 下次刷新祝福次数时间

    var recordTime: Long = 0,   // 上次记录时间
    var rewardStageList: LinkedList<Int> = LinkedList(),    // 已经领奖的阶段
    var score: Long = 0,     // 贡献值
    var bossHurt: Long = 0,    // 对boss伤害
)
data class PlayerArmyActivityVo(
    var joinSession: Int = 0,           // 本次参与的活动
    var joinAllianceId: Long = 0,   // 本次参与的活动联盟id
    var score: Long = 0,             // 玩家积分
    var scoreUpdateTime: Long = 0,  // 积分更新时间
    var loseCount: Int = 0,         // 失败次数
    var receivedRewardList: LinkedList<ArmyActivityScoreRecord> = LinkedList()  // 已经领取的奖励
)
data class PlayerBigArmsRaceData(
    var activityTypeId: Int = 0,
    var start: Long = 0,
    var over: Long = 0L,
    var alceScoreBanUntil: Long = 0, // 帮会积分累计禁止截止时间
    var stageMap: HashMap<Int, PlayerBigArmsRaceStageData> = hashMapOf(), // stage -> stageData
)
data class PlayerBigArmsRaceStageData(
    var stage: Int = 0,
    var score: Long = 0, // 自身累计积分(不受玩家退出联盟的影响)
    var upScore : Long = 0, // 上榜积分，一旦退盟直接置0且从榜单移除并禁榜
    var scoreUpdate: Long = 0L, // 积分变动时间
    var rewardScoreList: LinkedList<Int> = LinkedList(), // 已领取的阶段积分进度奖励对应的档位积分
)
data class SmallBlackVo(
    var activityId: Int = 0,
    var chooseLv: Int = 0, // 选择的难度
    var nowStep: Int = 0, // 打到第几关
    var posX: Int = 1,
    var posY: Int = 1,
    var overTime: Long = 0, // 消失时间
    var mapId: Long = 0,
    var hisMaxLv: Int = 0, // 历史最高通关级别
)
data class PlayerCapitalData(
    var votingValue: Int = 0,
    var lastVotingTime: Long = 0,
    var scoreMap: HashMap<Int, Long> = hashMapOf(), // 王城积分
)
data class AllianceArpgVo(
    var allianceSecretStep: Int = 0, // 联盟秘境进度
    val allianceSecretRewardList: LinkedList<Int> = LinkedList(), // 联盟秘境领过的大奖励
)
data class ArmyActivityScoreRecord(
    var playerScore: Long = 0,
    var allianceScore: Long = 0
)
// 活动随机掉落数据
class WorldPurActivityRandomDropRecord(
    var day: Int = 0, // 活动的第几天(活动开启当日算第一天)
    var wayNumMap: HashMap<Int, Int> = hashMapOf(), // 途径(com.point18.slg2d.common.constg.ActivityDropRandomWay)->道具已掉落数量
)
data class PlayerJjc(
    var score: Int = 0,    // 我的积分
    var fightCount: Int = 0, // 剩余战斗次数
    var lastFightTime: Long = 0, // 上次战斗时间
    var buyCount: Int = 0, // 本日购买的次数
    var lastBuyTime: Long = 0, // 上次购买刷新次数时间
    var myOppPlayerIdList: LinkedList<Long> = LinkedList(), // 我的对手
    var myRevengeMap: HashMap<Long, Int> = hashMapOf(), // 我的可复仇对象id
)
data class WorldBossData(
    var todayHurtNum: Long = 0,    // 今日伤害值
    var todayHurtCount: Int = 0,    // 今日攻击次数
    var lastHurtTime: Long = 0, // 上次伤害时间
    var nextRefTime: Long = 0,  // 下次刷新时间
    var hurtDataMap: HashMap<Int, WorldBossHurtData> = hashMapOf(),
)

data class WorldBossHurtData(
    var maxHurt: Long = 0, // 历史最高伤害值
    var receivedHurtRewardList: LinkedList<Long> = LinkedList(),    // 已经领取过的成就奖励列表
)
data class FarmRecord(
    var resId: Int = 0,
    var time: Long = 0,
    var x: Int = 0,
    var y: Int = 0,
    var res: String = "",
    var realRes: String = ""
)
data class JoinRelicRewardData(
    var rewardCount: Int = 0,
    var refTime: Long = 0
)
data class MassData(
    var joinIndex: Long = 0, // 加入的索引，用于自动加入排序
    var startAutoJoinTime: Long = 0,    // 开启自动加入的时间
    var joinEvenIfNoReward: Int = 1,    // 无奖励也加入
    var autoJoinTypeList: LinkedList<Int> = LinkedList(),   // 自动加入的类别列表
    var selectAutoJoinArmyPlanList: LinkedList<Long> = LinkedList(), // 选择的自动加入的部队列表
    var joinRelicRewardDataMap: HashMap<Int, JoinRelicRewardData> = hashMapOf() // 加入集结奖励记录
)
data class RelicData(
    var nextRefTime: Long = 0,      // 下次刷新时间
    var todayAtkMap: HashMap<Int, Int> = hashMapOf(),   // 今日攻击次数
    var totalKillMap: HashMap<Int, Int> = hashMapOf()   // 累计击杀记录
)
data class BossData(
    var maxKillLv: Int = 0, // 最大击杀等级
    var nextRefTime: Long = 0,      // 下次刷新时间
    var todayAtkMap: HashMap<Int, Int> = hashMapOf(),   // 今日攻击次数
)
data class DailyCollectRecord(
    var operTime: Long = 0,
    var collectCount: Int = 0, // 当天采集次数
    var collectResNumMap: HashMap<Int, Long> = hashMapOf() // 当天采集数
)
data class FarmData(
    var maxKillLv: Int = 0, // 最高攻占的资源矿等级
    var realResMap: HashMap<Int, Long> = HashMap(),
    var receiveTime: Long = 0,

    var farmMailId: Long = 0,
    var farmRecordList: LinkedList<FarmRecord> = LinkedList(),
    var dailyFarmRecord: DailyCollectRecord = DailyCollectRecord()
)
data class BigGiftReward(
    var giftId: Int = 0,
    var bigGiftLv: Int = 0
)
data class ObtainRecordInfo(
    var lastObtainTime: Long = 0L,  // 上次获得的时间
    var todayObtainedNum: Long = 0L  // 本日已获得的数量
)
data class AllianceGiftStateVo(
    var id: Long = 0,
    var giftId: Int = 0,
    var rewards: String = "",   // 奖励信息
    var overTime: Int = 0,  // 消失时间
    var rewarded: Int = 1
)
@TableName("w_player")
data class W_Player(
    @TableId(type = IdType.ASSIGN_ID)
    @TableField("id")
    var id: Long,

    @TableField("world_id")
    var worldId: Long,

    @TableField("aav")
    var aav: Int,

    @TableField("unit_task_id")
    var unitTaskId: Int,      // 当前已完成全部章节任务的的章节的模板ID,上一章的模板id,嗯就是当前章节-1，当前是第1章的话这个值就是0

    @TableField("leave_alliance_count")
    var leaveAllianceCount: Int, // 玩家离帮次数

    @TableField("next_join_alliance_time")
    var nextJoinAllianceTime: Long, // 下次可加入联盟时间

    @TableField("alliance_at")
    var allianceAt: Long, // 加入联盟时间

    
    @TableField("guide_list")
    var guideList: String,    // 新手引导客户端已走过的步数

    @TableField("combine_mail_id")
    var combineMailId: Long,    // 合并到的邮件id

    // 联盟科技相关字段
    @TableField("now_effect_num")
    var nowEffectNum: Int, // 剩余可捐献次数

    @TableField("last_effect_time")
    var lastEffectTime: Long, // 上次结算时间

    @TableField("today_num")
    var todayNum: Long, // 今天获得的科技值

    @TableField("last_get_time")
    var lastGetTime: Long, // 上次捐献的时间

    @TableField("today_donate_time")
    var todayDonateTime: Int, // 今日捐献次数

    // 联盟礼物
    
    @TableField("alliance_gift_map")
    var allianceGiftMap: String,

    @TableField("delM_max_id")
    var delMaxId: Long, // 删除的最大id

    
    @TableField("del_id_map")
    var delIdMap: String,  // 已删除的id集合，用于标记错开删除的酷礼物

    @TableField("today_open_gift_count")
    var todayOpenGiftCount: Int,    // 今天开的普通礼物的次数

    @TableField("ref_open_gift_count_time")
    var refOpenGiftCountTime: Long,      // 下次刷新开启普通礼物次数的时间

    @TableField("invite_time")
    var inviteTime: Long,   // 上次发送联盟邀请的时间

    @TableField("waijiao_count")
    var waijiaoCount: Int,  //今天外交次数

    @TableField("last_waijiao_time")
    var lastWaijiaoTime: Long,  //上次外交时间

    @TableField("read_diplomacy_time")
    var readDiplomacyTime: Long,  //阅读外交的时间

    @TableField("last_alliance_boss_reward_index")
    var lastAllianceBossRewardIndex: Int,  // 上次获得联盟boss奖励的届数

    
    @TableField("coin_lmt_map")
    var coinLmtMap: String, // 联盟币 key: 行为 eg.ALLIANCE_ACTION_TEC_DONATE

    
    @TableField("big_gift_strings_list")
    var bigGiftStringsList: String,

    @TableField("revive_task_score")
    var reviveTaskScore: Int,    // 复兴任务积分

    @TableField("revive_task_id")
    var reviveTaskId: Int,    // 复兴任务领取掉的id 初始是0

    @TableField("next_npc_city_daily_reward_time")
    var nextNpcCityDailyRewardTime: Long,  // 上次领取联盟占领npc城池奖励的时间

    
    @TableField("farm_data")
    var farmData: String,

    
    @TableField("boss_data")
    var bossData: String,

    
    @TableField("relic_data")
    var relicData: String,

    
    @TableField("mass_data")
    var massData: String,

    
    @TableField("world_boss_data")
    var worldBossData: String,

    
    @TableField("player_alliance_competition")
    var playerAllianceCompetition: String,

    @TableField("donate_score")
    var donateScore: Long = 0, // 总捐献所得积分值

    @TableField("npc_city_score")
    var npcCityScore: Long = 0, // NPC城战斗所得贡献值

    @TableField("npc_city_day_score")
    var npcCityDayScore: Long = 0, // NPC城战斗今日所得贡献值

    @TableField("npc_city_week_score")
    var npcCityWeekScore: Long = 0, // NPC城战斗本周所得贡献值

    @TableField("combined_global_buff_id")
    var combinedGlobalBuffId: Long = 0, // 已经合并到的全局buffId(用于有效果的buff)

    @TableField("expire_time")
    var expireTime: Long = 0,   // 过期时间，用于清除过期跨服数据

    
    @TableField("remove_global_buff_ids")
    var removeGlobalBuffMap: String,   // 移除的全局buffId列表(用于无效果的buff)

    
    @TableField("player_jjc")
    var playerJjc: String,

    @TableField("donate_day_score")
    var donateDayScore: Long = 0, // 今日捐献所得积分值

    @TableField("donate_week_score")
    var donateWeekScore: Long = 0, // 本周捐献所得积分值

    @TableField("friend_apply_require_lv")
    var friendApplyRequireLv: Int = 0, // 好友申请所需的主堡等级

    
    @TableField("alliance_arpg_vo")
    var allianceArpgVo: String,

    
    @TableField("player_capital")
    var playerCapitalData: String,   // 王城信息

    
    @TableField("small_black_vo")
    var smallBlackVo: String,

    
    @TableField("big_arms_race_data")
    var bigArmsRaceData: String,

    
    @TableField("player_army_activity")
    var playerArmyActivity: String,

    
    @TableField("player_expedition")
    var playerExpedition: String,

    
    @TableField("activity_data")
    var activityDataMap: String,

    
//    @TableField("room_chat_records", typeHandler = JacksonTypeHandler::class)
//    var roomChatRecordMap: HashMap<Long, Int>,
    @TableField("room_chat_records")
    var roomChatRecordMap: String,
) {

}


fun main() {
    val inputStream = FileInputStream("src/main/resources/mybatis-config.xml")
    val sqlSessionFactory = MybatisSqlSessionFactoryBuilder().build(inputStream)

    val sqlSession: SqlSession = sqlSessionFactory.openSession()
    try {
        val playerMapper = sqlSession.getMapper(WPlayerMapper::class.java)
        var l1 = System.currentTimeMillis()
        // QueryWrapper<W_Player>().gt("id", 0)
//        val selectList = playerMapper.selectList(null)
        val selectList = playerMapper.selectAllPlayers()

        val mapper = jacksonObjectMapper()
        selectList.forEach {
            mapper.readValue(it.guideList, LinkedList<Int>()::class.java)
            mapper.readValue(it.allianceGiftMap, HashMap<Long, AllianceGiftStateVo>()::class.java)
            mapper.readValue(it.delIdMap, HashMap<Long, Int>()::class.java)
            mapper.readValue(it.coinLmtMap, HashMap<Int, ObtainRecordInfo>()::class.java)
            mapper.readValue(it.bigGiftStringsList, LinkedList<BigGiftReward>()::class.java)
            mapper.readValue(it.allianceGiftMap, HashMap<Long, AllianceGiftStateVo>()::class.java)
            mapper.readValue(it.farmData, FarmData()::class.java)
            mapper.readValue(it.bossData, BossData()::class.java)
            mapper.readValue(it.relicData, RelicData()::class.java)
            mapper.readValue(it.massData, MassData()::class.java)
            mapper.readValue(it.worldBossData, WorldBossData()::class.java)
            mapper.readValue(it.relicData, RelicData()::class.java)

            mapper.readValue(it.removeGlobalBuffMap, HashMap<Long, Int>()::class.java)
            mapper.readValue(it.playerJjc, PlayerJjc()::class.java)
            mapper.readValue(it.allianceArpgVo, AllianceArpgVo()::class.java)
            mapper.readValue(it.playerCapitalData, PlayerCapitalData()::class.java)
            mapper.readValue(it.smallBlackVo, SmallBlackVo()::class.java)
            mapper.readValue(it.bigArmsRaceData, PlayerBigArmsRaceData()::class.java)
            mapper.readValue(it.playerArmyActivity, PlayerArmyActivityVo()::class.java)
            mapper.readValue(it.playerExpedition, PlayerExpeditionVo()::class.java)
            val l2 = mapper.readValue(it.activityDataMap, HashMap<Int, WorldPurActivityData>()::class.java)
            val l1 = mapper.readValue(it.roomChatRecordMap, HashMap<Long, Int>()::class.java)
        }

//        val user = User(13890L, 1231L,"Alicesfdasdf","Alicegsdg",
//            "Aliceasfsa","Alicesdafsgvsdgs",
//            listOf("admin", "userfasdfgs","Alicesfdasdf","Alicegsdg",))
//        val json = mapper.writeValueAsString(user)
//        for (i in 1..selectList.size * 10) {
//            val user1 = mapper.readValue(json, User::class.java)
//        }

        var l2 = System.currentTimeMillis()

        println("${selectList.size}  ---  ${l2 - l1}")

    } finally {
        sqlSession.close()
    }
}

